<template>
  <div>
    <MyHeader
      background="pink"
      fontColor="yellow "
      title="购 物车案例"
    ></MyHeader>
    <div class="main">
      <MyGoods v-for="obj in list" :key="obj.id" :goodsObj="obj"></MyGoods>
    </div>
    <MyFooter @changeCheck="changeFn" :arr="list"></MyFooter>
  </div>
</template>

<script>
import MyFooter from "./components/MyFooter";
import MyGoods from "./components/MyGoods";
import MyHeader from "./components/MyHeader";
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  data() {
    return {
      list: [], //保存全部的商品数据
    };
  },
  created() {
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      //数据保存到list变量
      this.list = res.data.list;
    });
  },
  methods: {
    changeFn(bool) {
      this.list.forEach((obj) => (obj.goods_state = bool));
    },
  },
};
</script>

<style scoped>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
div {
  background-color: skyblue;
}
</style>